#!/bin/bash

if [ "$(whoami )" = "root" ];then
	echo " "
else
	echo "Operation not permitted,are you root?"
	exit 1
fi


if [ "$2" = "32" ];then
	ARCH=i386
elif [ "$2" = "64" ];then
	ARCH=x86_64
else
	echo "Usage: ./pack.sh rpm/deb 32/64"
	exit 1
fi
	

if [ "$1" = "rpm" ];then
	VERSION=1.0.0.el6
	PACNAME=LM_VMKey_Server-${VERSION}.${ARCH}.rpm

	rpmdev-setuptree
	rm ~/rpmbuild/SOURCES/LM_VMKey_Server -rf
	cp ./LM_VMKey_Server/ ~/rpmbuild/SOURCES -rf
	
	rpmbuild -bb ./LM_VMKey_Server.spec
	cp ~/rpmbuild/RPMS/*/LM_VMKey_Server*.rpm ./package/${PACNAME}
	
elif [ "$1" = "deb" ];then
	VERSION=1.0.0.ubuntu10.04.4
	PACNAME=LM_VMKey_Server-${VERSION}.${ARCH}

	cp LM_VMKey_Server ${PACNAME} -rf
	chmod 777 ${PACNAME} -R
	chmod 755 ${PACNAME}/DEBIAN -R
	dpkg -b ./package/${PACNAME}

	rm ${PACNAME} -rf 
else
	echo "Usage: ./pack.sh rpm/deb 32/64"
fi



